package com.cheung.leetcode.day;

import  org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.day
 * @Author :  cheungming
 * @CreateTime : 2024-07-14 13:17:24
 * @Description : 每日 一题
 * @Version : 1.0
 */
public class Code807Test {

    public int maxIncreaseKeepingSkyline(int[][] grid) {


        int[] rowMax = new int[grid.length];
        for (int i = 0; i < grid.length; i++) {
            int max = 0;
            for (int j = 0; j < grid[i].length; j++) {
                max = Math.max(max, grid[i][j]);
            }
            rowMax[i] = max;
        }

        int[] colMax = new int[grid[0].length];
        for (int i = 0; i < grid[0].length; i++) {
            int max = 0;
            for (int j = 0; j < grid.length; j++) {
                max = Math.max(max, grid[j][i]);
            }
            colMax[i] = max;
        }

        int sum = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                sum += Math.min(rowMax[i], colMax[j]) - grid[i][j];
            }
        }

        return sum;
    }

    @Test
    public void test1() {
        int[][] grid = {{3, 0, 8, 4}, {2, 4, 5, 7}, {9, 2, 6, 3}, {0, 3, 1, 0}};
        assert maxIncreaseKeepingSkyline(grid) == 35;
    }

}
